package com.apes.framework.plugin.express;

import com.apes.framework.api.SpringManager;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.IExpressContext;
import org.springframework.util.LinkedCaseInsensitiveMap;

import java.util.Map;

/**
 * 功能：ExpressContext
 *
 * @author xul
 * @create 2018-12-05 15:14
 */
public class ApesExpressContext<K extends String, V> implements IExpressContext<K, V> {
    private final Map context = new LinkedCaseInsensitiveMap();

    public ApesExpressContext() {
    }

    public ApesExpressContext(Map<K, V> context) {
        this.context.putAll(context);
    }


    @Override
    public V put(K k, V v) {
        return (V) context.put(k, v);
    }

    @Override
    public V get(Object name) {
        Object result = context.get(name);
        if (result == null && SpringManager.containsBean((String) name)) {
            result = SpringManager.getBean((String) name);
        }
        return (V) result;
    }
}
